<!-- <template>
	<view>
		<h1>instructor_index</h1>
		<view>{{token}}--{{uid}}--{{name}}</view>
		<button v-on:click="test()">测试</button>
	</view>
</template> -->
<template>
	<view>
		<view>
			<uni-section class="mb-10" v-bind:title="name" :sub-title="teacher.name" type="line"></uni-section>
		</view>
		<view class="flex-center" style="padding-top: 10rpx;">
			<zkml-button bgColor="#5866fa" title="扫一扫" titleColor='#ffffff' @btnClick="scan()"></zkml-button>
		</view>
		<view>
			<custom-tabs type="c1" :value="Opindex" @change="changeIndex">
				<custom-tab-pane label="确认请假(最近一次)" name="c1_1">
					<view style="padding-top: 10rpx;">
						<uni-card title="信息" extra="无信息" v-if="show ==0">
							<text>没有接受到信息</text>
						</uni-card>
						<uni-card title="信息" extra="最近的信息" v-if="show ==1">
							<view v-for="(item,index) in leaveInfo ">
								<uni-card title="请假记录" :extra="item.action">
									<view class="test-component flex-center">
										<hm-news-card>
											<view><text>班级:{{item.request_class_name}}</text></view>
											<view><text>姓名:{{item.request_name}}</text></view>
											<view><text>开始时间:{{item.start_time}}</text></view>
											<view><text>结束时间:{{item.end_time}}</text></view>
											<view><text>原因:{{item.msg}}</text></view>
											<view><text>辅导员:{{item.teacher_name}} 是否确认:{{item.teacher_confirm}}</text>
											</view>
											<view><text>辅导员确认时间:{{item.teacher_confirm_time}}</text></view>
											<view><text>是否返校:{{item.return_confirm}}
													确认人:{{item.return_confirm_name}}</text></view>
											<view><text>返校确认时间:{{item.return_confirm_time}}</text></view>
											<view><text>假条创建时间:{{item.CreatedAt|formatTimer}}</text></view>
											<button class="save" @tap="teacherConfirm(item.ID)"
												v-if="!item.teacher_confirm"> 确 认 </button>
										</hm-news-card>
									</view>
								</uni-card>
							</view>
						</uni-card>
					</view>
				</custom-tab-pane>
				<custom-tab-pane label="取消请假(最近一次)" name="c1_2">
					<view style="padding-top: 10rpx;">
						<uni-card title="信息" extra="无信息" v-if="Rshow ==0">
							<text>没有接受到信息</text>
						</uni-card>
						<uni-card title="信息" extra="最近的信息" v-if="Rshow ==1">
							<view v-for="(item,index) in leaveInfoR ">
								<uni-card title="请假记录" :extra="item.action">
									<view class="test-component flex-center">
										<hm-news-card>
											<view><text>班级:{{item.request_class_name}}</text></view>
											<view><text>姓名:{{item.request_name}}</text></view>
											<view><text>开始时间:{{item.start_time}}</text></view>
											<view><text>结束时间:{{item.end_time}}</text></view>
											<view><text>原因:{{item.msg}}</text></view>
											<view><text>辅导员:{{item.teacher_name}} 是否确认:{{item.teacher_confirm}}</text>
											</view>
											<view><text>辅导员确认时间:{{item.teacher_confirm_time}}</text></view>
											<view><text>是否返校:{{item.return_confirm}}
													确认人:{{item.return_confirm_name}}</text></view>
											<view><text>返校确认时间:{{item.return_confirm_time}}</text></view>
											<view><text>假条创建时间:{{item.CreatedAt|formatTimer}}</text></view>
											<button class="save" @tap="opConfirm(item.ID)"
												v-if="item.teacher_confirm&&!item.return_confirm"> 确 认 </button>
										</hm-news-card>
									</view>
								</uni-card>
							</view>
						</uni-card>
					</view>
				</custom-tab-pane>
				<custom-tab-pane label="班级" name="c1_3">
					<view style="padding-top: 10rpx;">
					<!-- 	<uni-card title="信息" extra="无信息" v-if="Cshow ==0">
							<text>没有接受到信息</text>
						</uni-card> -->
							<view v-for="(item,index) in classInfo ">
								<uni-card title="班级信息" extra="无">
									<view class="test-component flex-center">
										<hm-news-card>
											<view><text>学院:{{item.college}}</text></view>
											<view><text>班级:{{item.name}}</text></view>
											<view><text>班级总人数:{{item.people_count}}</text></view>
											<view><text>班级请假人数:{{item.leave_count}}</text></view>
											<view><text>班级现人数:{{item.now_people_count}}</text></view>
											<button class="save" @tap="opConfirm(item.ID)"
												v-if="item.teacher_confirm&&!item.return_confirm"> 确 认 </button>
										</hm-news-card>
									</view>
								</uni-card>
							</view>
					</view>
				</custom-tab-pane>
			</custom-tabs>
		</view>
	</view>
</template>

<script>
	import zkmlButton from '@/components/zkml-Button/zkml-Button.vue'
	export default {
		components: {
			zkmlButton
		},
		data() {
			return {
				teacher: {
					name: "未填写",
				},
				leave: {
					wx_open_id: "",
					page: 1,
					size: 1,
					no_confirm: 1,
				},
				leaveR: {
					wx_open_id: "",
					page: 1,
					size: 1,
				},
				Opindex: 0,
				token: "",
				uid: "",
				name: "",
				show: 0,
				Rshow: 0,
				Cshow:0,
				leaveInfo: [{
					ID: "",
					title: "",
					CreatedAt: "",
					request_id: "",
					request_name: "",
					request_class_id: "",
					request_class_name: "",
					start_time: "",
					end_time: "",
					msg: "",
					teacher_id: "",
					teacher_name: "",
					teacher_confirm: "",
					teacher_confirm_time: "",
					return_confirm: "",
					return_confirm_id: "",
					return_confirm_name: "",
					return_confirm_time: "",
					action: "",
				}],
				leaveInfoR: [{
					ID: "",
					title: "",
					CreatedAt: "",
					request_id: "",
					request_name: "",
					request_class_id: "",
					request_class_name: "",
					start_time: "",
					end_time: "",
					msg: "",
					teacher_id: "",
					teacher_name: "",
					teacher_confirm: "",
					teacher_confirm_time: "",
					return_confirm: "",
					return_confirm_id: "",
					return_confirm_name: "",
					return_confirm_time: "",
					action: "",
				}],
				classInfo:[{
					CreatedAt:"",
					ID:"",
					college:"",
					grade:"",
					leave_count:"",
					name:"",
					now_people_count:"",
					people_count:"",
				}]
			}
		},
		methods: {
			changeIndex: function(e) {
				this.Opindex = e.value
				if (this.Opindex == 2) {
					this.getClassInfo()
				}
			},
			formatDate: function(value) {
				var index = value.lastIndexOf("T");
				value = value.substring(0, index);
				// console.log(value);
				return value;
			},
			getLeaveInfo: function() {
				let that = this
				this.$myHttp({
					url: '/leave/student/search',
					method: "post",
					data: this.leave
				}).then((res) => {
					var result = res.data
					if (result.data.length == 0) {
						uni.showToast({
							title: "没有数据了",
							duration: 3000,
							icon: 'none'
						})
						that.show = 0
						return
					}
					that.leaveInfo = result.data
					// this.select()
				})
			},
			scan: function() {
				//判断情况
				if (this.Opindex == 0) {
					uni.scanCode({
						success: (res) => {
							this.leave.wx_open_id = res.result
							this.getLeaveInfo()
							this.show = 1
						}
					})
				}
				if (this.Opindex == 1) {
					uni.scanCode({
						success: (res) => {
							this.leaveR.wx_open_id = res.result
							this.opConfirmOP()
							this.Rshow = 1
						}
					})
				}
			},
			teacherConfirm: function(i) {
				// console.log(i)
				let that = this
				this.$myHttp({
					url: '/leave/teacher/op',
					method: "post",
					data: {
						leave_id: i
					}
				}).then((res) => {
					var result = res.data
					if (result.code == 1000) {
						that.teacherConfirmOP()
					}
				})
			},
			opConfirm: function(i) {
				// console.log(i)
				let that = this
				this.$myHttp({
					url: '/leave/op/op',
					method: "post",
					data: {
						"leave_id": i,
						"return_name": this.teacher.name,
					}
				}).then((res) => {
					var result = res.data
					if (result.code == 1000) {
						that.opConfirmOP()
					}
				})
			},
			teacherConfirmOP: function(i) {
				let that = this
				this.leave.no_confirm = 0
				this.$myHttp({
					url: '/leave/student/search',
					method: "post",
					data: this.leave
				}).then((res) => {
					var result = res.data
					if (result.data.length == 0) {
						uni.showToast({
							title: "没有数据了",
							duration: 3000,
							icon: 'none'
						})
						that.show = 0
						return
					}
					that.leaveInfo = result.data
				})
			},
			opConfirmOP: function(i) {
				let that = this
				this.$myHttp({
					url: '/leave/student/search',
					method: "post",
					data: this.leaveR
				}).then((res) => {
					var result = res.data
					if (result.data.length == 0) {
						uni.showToast({
							title: "没有数据了",
							duration: 3000,
							icon: 'none'
						})
						that.Rshow = 0
						return
					}
					that.leaveInfoR = result.data
				})
			},
			//获得班级信息
			getClassInfo:function(){
				let that = this
				this.$myHttp({
					url: '/class/search/teacher/wx',
					method: "post",
					data: {
						"teacher_id":this.uid
					}
				}).then((res) => {
					var result = res.data
					if (result.data.length == 0) {
						uni.showToast({
							title: "没有数据了",
							duration: 3000,
							icon: 'none'
						})
						that.Rshow = 0
						return
					}
					that.classInfo = result.data
					that.Cshow = 1
					// console.log(result)
				})
			}
		},
		filters: {
			formatTimer: function(value) {
				let date = new Date(value);
				let y = date.getFullYear();
				let MM = date.getMonth() + 1;
				MM = MM < 10 ? "0" + MM : MM;
				let d = date.getDate();
				d = d < 10 ? "0" + d : d;
				let h = date.getHours();
				h = h < 10 ? "0" + h : h;
				let m = date.getMinutes();
				m = m < 10 ? "0" + m : m;
				let s = date.getSeconds();
				s = s < 10 ? "0" + s : s;
				return y + "-" + MM + "-" + d + " " + h + ":" + m;
			},
		},
		created() {
			this.token = uni.getStorageSync('token');
			this.uid = uni.getStorageSync('teacher_id');
			this.teacher.name = uni.getStorageSync('teacher_name');
		}
	}
</script>

<style>
	.flex-center {
		display: flex;
		flex-direction: row;
		justify-content: center;
	}

	.flex-right {
		display: flex;
		flex-direction: row;
		justify-content: right;
	}
</style>